import { defineConfig ,loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { svgBuilder } from './src/plugins/svgBuilder'
import {resolve} from 'path'
import Components from 'unplugin-vue-components/vite' // 按需加载自定义组件
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import AutoImport from "unplugin-auto-import/vite"

export default defineConfig(({ command, mode }) => {
    //检查process.cwd()路径下.env.development.local、.env.development、.env.local、.env这四个环境文件
    loadEnv(mode, process.cwd());
    //返回vite配置
    return {
        publicPath: "/",
        plugins: [
            vue(),
            svgBuilder('./src/icons/svg/'),
             // 按需引入
            Components({
                deep: true, // 搜索子目录
                dirs: ['src/components'], // 按需加载的文件夹
                resolvers: [ ElementPlusResolver() ] // ElementPlus按需加载
            }),
            AutoImport ({
                imports: ["vue", "vue-router","pinia"], //自动引入vue的ref、toRefs、onmounted等，无需在页面中再次引入
                resolvers:[ElementPlusResolver()]
            })
        ],
        resolve:{//路径别名
            alias:{
                '@': resolve(__dirname,'./src')
            }
        },
    }
})

